package cn.xmy.demo01.servlet;

import cn.xmy.demo01.pojo.Forum;
import cn.xmy.demo01.service.ForumService;
import cn.xmy.demo01.service.impl.ForumServiceImpl;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.sql.SQLException;
import java.util.List;
@WebServlet("/AddForum")
public class AddForum extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ForumService forumService=new ForumServiceImpl();
        String id=request.getParameter("id");
        String name=request.getParameter("name");
        Forum forum=new Forum(id,name);
        int rows=0;
        try {
            rows=forumService.addForum(forum);
        } catch (SQLException e) {
            throw new RuntimeException(e);
        } catch (ClassNotFoundException e) {
            throw new RuntimeException(e);
        }
        request.getRequestDispatcher("home.jsp").forward(request,response);
    }
}